package utils

/*
Copyright 2021-2025 The k8gb Contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
*/

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestParseIPAddresses(t *testing.T) {
	tests := []struct {
		name          string
		input         string
		expected      []string
		expectedError bool
	}{
		{
			"single valid IP address",
			"10.0.0.1",
			[]string{"10.0.0.1"},
			false,
		},
		{
			"multiple valid IP addresses",
			"10.0.0.1,10.0.0.2",
			[]string{"10.0.0.1", "10.0.0.2"},
			false,
		},
		{
			"out of 0-255 range",
			"256.256.256.256",
			[]string{},
			true,
		},
		{
			"invalid characters",
			"test.gslb.test.gslb",
			[]string{},
			true,
		},
		{
			"valid and invalid IP addresses",
			"10.0.0.1,test.gslb.test.gslb",
			[]string{},
			true,
		},
		{
			"multiple valid IP addresses with additional comma",
			"10.0.0.1,10.0.0.2,",
			[]string{},
			true,
		},
	}

	// Run each test case
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			ipAddresses, err := ParseIPAddresses(tt.input)
			if tt.expectedError {
				assert.Error(t, err)
			} else {
				assert.NoError(t, err)
			}

			assert.Equal(t, tt.expected, ipAddresses)
		})
	}
}
